package com.stormrage.edu.dao.ent.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.ent.EntEnterpriseDao;
import com.stormrage.entity.ent.EntEnterprise;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: EntEnterpriseDaoImpl.java
 * @Package com.stormrage.edu.dao.ent.impl
 * @Description: 公司 Dao
 * @author www.stormragetech.com
 * @date 2016年4月13日
 * @version V1.0
 */
@Repository
public class EntEnterpriseDaoImpl extends MysBaseDao implements EntEnterpriseDao {

	private static final Logger logger = LoggerFactory.getLogger(EntEnterpriseDaoImpl.class);

	@Override
	public Integer create(final EntEnterprise arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EntEnterpriseDao 】- 【 Create 】- 开始运行 ");

		final String query = "INSERT INTO ent_enterprise (enterprise, phone, email) VALUES"
				+ " (:enterprise, :phone, :email)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】- 【 EntEnterpriseDao 】- 【 Create 】- 完成运行 ");
		return index;

	}

	@Override
	public void update(final EntEnterprise arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EntEnterpriseDao 】- 【 Update 】- 开始运行 ");

		final String query = "UPDATE ent_enterprise SET phone = :phone, email = :email WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, arg0);
		logger.debug(" 【 Dao 】- 【 EntEnterpriseDao 】- 【 Update 】- 完成运行 ");

	}

	@Override
	public EntEnterprise queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EntEnterpriseDao 】- 【 QueryById 】- 开始运行 ");

		final String query = "SELECT * FROM ent_enterprise WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		EntEnterprise entity = queryObject(query, EntEnterprise.class, map);
		logger.debug(" 查询结果为 " + entity);

		return entity;

	}

	@Override
	public EntEnterprise queryByName(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EntEnterpriseDao 】- 【 QueryByName 】- 开始运行 ");

		final String query = "SELECT * FROM ent_enterprise WHERE enterprise = :name";
		logger.debug(" 数据库执行语句为 " + query);

		EntEnterprise entity = queryObject(query, EntEnterprise.class, map);
		logger.debug(" 查询结果为 " + entity);

		return entity;

	}

	@Override
	public List<EntEnterprise> queryList() throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EntEnterpriseDao 】- 【 QueryList 】- 开始运行 ");

		final String query = "SELECT * FROM ent_enterprise";
		logger.debug(" 数据库执行语句为 " + query);

		List<EntEnterprise> array = queryList(query, EntEnterprise.class);
		logger.debug(" 查询结果为 " + array);

		return array;

	}

}
